var mgeUser = {
	tableid : "table1",
	layerindex : null,
	bsTable : null,
	idselect : null
};

mgeUser.clearInputs = function() {
	var ipts = $("#form_opt").find("input");
	ipts.each(function(i, v) {
		$(v).val("");
		var er = $(v).next();
		if (er != null) {
			er.remove();
		}
		var hs = $(v).parents(".col-md-8");
		hs.removeClass("has-success");
		hs.removeClass("has-error");
	});
}

mgeUser.queryParams = function() {
	return cmm.serializeObject($("#form_search"));
}
mgeUser.resHeigth = function() {
	var he = $(window).height() - ($("#divsearch").height() + 20);
	return he;
}
mgeUser.refresh = function(pageNumber) {
	mgeUser.bsTable.refresh(mgeUser.queryParams(), pageNumber);
}
mgeUser.load = function() {
	mgeUser.bsTable.load(mgeUser.queryParams());
}
var myLayout;
$(function() {
	myLayout = $('body').layout({
		north__minSize : 50,
		north__maxSize : 400,
		togglerContent_open : '<div class="ui-icon"></div>',
		togglerContent_closed : '<div class="ui-icon"></div>'
	// , spacing_open: 10
	// , spacing_closed: 10
	});
	var lay = layer.load({
		shade : [ 0.1 ]
	});
	$
			.ajax({
				url : ctx + "/mge/adx/rmrb/columns",
				data : {
					s_name : "rmrbtablectn"
				},
				dataType : 'json',
				type : 'post',
				success : function(d, st) {
					layer.close(lay);
					if (d.code == 200) {
						var colum = [];
						var fs = [];
						colum.push(fs);
						for ( var d3 in d.rows) {
							var d2 = d.rows[d3];
							var k = d2.columnName;
							if (k == "contents") {
								fs
										.push({
											title : d2.columnName,
											field : d2.columnName,
											width : "200px",
											align : 'center',
											valign : 'middle',
											formatter : function(v, r) {
												return "<div style='cursor: pointer;color:red' onclick='clikrow(\""
														+ r.id
														+ "\")'>点击查看</div>";
											}
										})
							} else {
								fs.push({
									title : d2.columnName,
									field : d2.columnName,
									width : "200px",
									align : 'center',
									valign : 'middle'
								})
							}
						}
						getData(colum);
					}
				},
				error : function(st) {
					layer.close(lay);
					layer.alert("请求失败，请重试或检查网络！");
				}
			})

	$("#form_search").on("submit", function(e) {
		mgeUser.bsTable.destroy()
		getData();
		return false;
	});
});
function clikrow(id) {
	var row = mgeUser.bsTable.idbst.bootstrapTable("getData");
	var he = $(window).height() - 50;
	var w = $(window).width() - 50;
	for ( var k in row) {
		if (row[k].id == id) {
			layer.open({
				type : 1,
				skin : 'layui-layer-rim', // 加上边框
				area : [ w + 'px', he + 'px' ], // 宽高
				content : row[k].contents
			});
		}
	}
}
function getData(column) {
	var bs = new BgdataTable();
	var opt = new BgOption(mgeUser.tableid, ctx
			+ "/mge/adx/rmrb/queryTablectn?rad=" + new Date().getTime(),
			column, mgeUser.queryParams(), mgeUser.resHeigth());
	opt.toolbarId = "table1Toolbar";
	bs.draw(opt);
	mgeUser.bsTable = bs;
}